{extend name='admin@main'}

{block name="content"}
<script>
layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '/upload/'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        return layer.msg('上传失败');
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
  
  //多图片上传
  upload.render({
    elem: '#test2'
    ,url: '/upload/'
    ,multiple: true
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
      });
    }
    ,done: function(res){
      //上传完毕
    }
  });
  
  //指定允许上传的文件类型
  upload.render({
    elem: '#test3'
    ,url: '/upload/'
    ,accept: 'file' //普通文件
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({ //允许上传的文件后缀
    elem: '#test4'
    ,url: '/upload/'
    ,accept: 'file' //普通文件
    ,exts: 'zip|rar|7z' //只允许上传压缩文件
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({
    elem: '#test5'
    ,url: '/upload/'
    ,accept: 'video' //视频
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({
    elem: '#test6'
    ,url: '/upload/'
    ,accept: 'audio' //音频
    ,done: function(res){
      console.log(res)
    }
  });
  
  //设定文件大小限制
  upload.render({
    elem: '#test7'
    ,url: '/upload/'
    ,size: 60 //限制文件大小，单位 KB
    ,done: function(res){
      console.log(res)
    }
  });
  
  //同时绑定多个元素，并将属性设定在元素上
  upload.render({
    elem: '.demoMore'
    ,before: function(){
      layer.tips('接口地址：'+ this.url, this.item, {tips: 1});
    }
    ,done: function(res, index, upload){
      var item = this.item;
      console.log(item); //获取当前触发上传的元素，layui 2.1.0 新增
    }
  })
  
  //选完文件后不自动上传
  upload.render({
    elem: '#test8'
    ,url: '/upload/'
    ,auto: false
    //,multiple: true
    ,bindAction: '#test9'
    ,done: function(res){
      console.log(res)
    }
  });
  
  //拖拽上传
  upload.render({
    elem: '#test10'
    ,url: '/upload/'
    ,done: function(res){
      console.log(res)
    }
  });
  
	//多文件列表示例
	var demoListView = $('#demoList'),
	uploadListIns = upload.render({
		elem: '#testList',
		url: '{:url("upload")}',
		accept: 'file',
		multiple: true,
		auto: false,
		bindAction: '#testListAction',
		choose: function(obj) {
			var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
				//console.log(obj);
				//读取本地文件
				obj.preview(function(index, file, result) {
			
				//console.log(index);
				
				var tr = $(['<tr id="upload-' + index + '">', '<td>' + file.name + '</td>', '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>', '<td>等待上传</td>', '<td>', '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>', '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>', '</td>', '</tr>'].join(''));

				//单个重传
				tr.find('.demo-reload').on('click',
				function() {
					obj.upload(index, file);
				});

				//删除
				tr.find('.demo-delete').on('click',
				function() {
					delete files[index]; //删除对应的文件
					tr.remove();
					uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
				});

				demoListView.append(tr);
			});
		},
		done: function(res, index, upload) {
			//console.log(index);
			
			//var files = this.files = upload.pushFile(); //将每次选择的文件追加到文件队列
			
			//console.log(upload);
			if (res.code == 0) { //上传成功
				var tr = demoListView.find('tr#upload-' + index),
				tds = tr.children();
				var str ='<input type="hidden" name="fileurl[]" value="'+res.url+'"><input type="hidden" name="user_id[]" value="'+res.user_id+'">';
				str +='<input type="hidden" name="original_name[]" value="'+res.original_name+'"><input type="hidden" name="fileext[]" value="'+res.extension+'">';
				str +='<input type="hidden" name="filesize[]" value="'+res.size+'"><input type="hidden" name="filename[]" value="'+res.save_name+'">';
				str +='<input type="hidden" name="md5code[]" value="'+res.md5+'"><input type="hidden" name="sha1code[]" value="'+res.sha1+'">';
				
				tds.eq(2).html('<span style="color: #5FB878;">上传成功'+str+'</span>');
				tds.eq(3).html('<a href="'+res.url+'" target="new">查看</a>&nbsp;<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'); //清空操作
				
				//删除
				tr.find('.demo-delete').on('click',
				function() {
					//delete this.files[index]; //删除对应的文件
					tr.remove();
					uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
				});
				
				return delete this.files[index]; //删除文件队列已经上传成功的文件
			}
			this.error(index, upload);
		},
		error: function(index, upload) {
			var tr = demoListView.find('tr#upload-' + index),
			tds = tr.children();
			tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
			tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
		}
	});
  
  //绑定原始文件域
  upload.render({
    elem: '#test20'
    ,url: '/upload/'
    ,done: function(res){
      console.log(res)
    }
  });
  
});
</script>





<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">

	<div class="layui-card-body think-box-shadow padding-left-40">
    <!--<div class="layui-card-body">-->
        <div class="layui-form-item">
            <label class="layui-form-label label-required">文件标题</label>
            <div class="layui-input-block">
                <input name="title" value='{$vo.title|default=""}' required placeholder="请输入文件标题" class="layui-input">
            </div>
        </div>
		

		
		
        <div class="layui-form-item nowrap">
            <label class="layui-form-label label-required">收文编号</label>
            <div class="layui-input-inline margin-right-0" style="width:120px">
                <input name="docno" value='{$vo.docno|default=""}' required placeholder="请输入收文编号" class="layui-input">
            </div>
			
            <label class="layui-form-label">来文编号</label>
            <div class="layui-input-inline margin-right-0" style="width:120px">
                <input type="text" name="doccode" value='{$vo.doccode|default=""}'  placeholder="来文编号" class="layui-input" >
            </div>

            <label class="layui-form-label">收文人</label>
            <div class="layui-input-inline margin-right-0" style="width:120px">
                <input type="text" name="docauthor" value='{$vo.docauthor|default=""}'  placeholder="" class="layui-input" >
            </div>
			
        </div>
		
		
        <div class="layui-form-item nowrap">
            <label class="layui-form-label label-required">收文日期</label>
            <div class="layui-input-inline margin-right-0" style="width:120px">
                <input type="text" data-date-input="date" name="docdate" value='{$vo.docdate|format_datetime='Y-m-d'|default=""}' required placeholder="收文日期" class="layui-input" >
            </div>
			
            <label class="layui-form-label label-required">成文日期</label>
            <div class="layui-input-inline margin-right-0" style="width:120px">
                <input type="text" data-date-input="date" name="issuedate" value='{$vo.issuedate|format_datetime='Y-m-d'|default=""}' placeholder="成文日期" class="layui-input" >
            </div>		
			
			
			
			
            <label class="layui-form-label ">紧急程度</label>
            <div class="layui-input-inline margin-right-0" style="width:120px">
			  <select name="jinji" lay-verify="required">
			  {notempty name='vo.id'}<option selected value="{$vo.jinji}">{$vo.jinji}</option>{/notempty}
				<option value=""></option>
				
				<option value="平件">平件</option>
				<option value="紧急">紧急</option>
				<option value="加急">加急</option>

			  </select>
            </div>
			
            <label class="layui-form-label ">密级</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
			  <select name="classes" lay-verify="required">
				
				{notempty name='vo.id'}<option selected value="{$vo.classes}">{$vo.classes}</option>{/notempty}
				<option value=""></option>

				<option value="公开">公开</option>
				<option value="不公开">不公开</option>
				<option value="保密">保密</option>
				<option value="绝密">绝密</option>

			  </select>
            </div>
			
        </div>
		
		
        <div class="layui-form-item">
            <label class="layui-form-label label-required">来文单位</label>
            <div class="layui-input-block">
                <input name="docunit" value='{$vo.docunit|default=""}' required placeholder="请输入来文单位" class="layui-input">
            </div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label ">主题词</label>
            <div class="layui-input-block">
                <input name="keywords" value='{$vo.keywords|default=""}' placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">备   注</label>
            <div class="layui-input-block">
                <input name="remark" value='{$vo.remark|default=""}' placeholder="" class="layui-input">
            </div>
        </div>


		<script src="__ROOT__/static/plugs/select/xm-select.js"></script>
		<script>
		var doccharger = xmSelect.render({
			el: '#doccharger', 
			name: 'doccharger',
			radio: true,
			layVerify: 'required',
			layVerType: 'tips',
			theme: {
				color: '#f37b1d',
			},
			paging: true,
			pageSize: 10,
			filterable: true,
			data: [
				{$str}
			]
		})
		
		
		var docleader = xmSelect.render({
			el: '#docleader', 
			name: 'docleader',
			max: 4,
			filterable: true,
			theme: {
				color: '#8dc63f',
			},
			paging: true,
			pageSize: 10,
			data: [
				{$str}
			]
		})
		
		
		var docread = xmSelect.render({
			el: '#docread', 
			filterable: true,
			name: 'docread',
			paging: true,
			pageSize: 10,
			data: [
				{$str}
			]
		})
		
		var docdo = xmSelect.render({
			el: '#docdo', 
			paging: true,
			pageSize: 10,
			filterable: true,
			name: 'docdo',
			theme: {
				color: '#e54d42',
			},
			
			data: [
				{$str}
			]
		})
		
		{if isset($vo) }
		docleader.setValue([ {$docleader} ])
		
		docread.setValue([ {$docread} ])
		
		docdo.setValue([ {$docdo} ])
		{/if}
		</script>

		
        <div class="layui-form-item">
            <label class="layui-form-label label-required">拟办人</label>
            <div class="layui-input-block">
			
                {if isset($vo) and isset($vo.doccharger)}
                <input disabled value='{$vo.doccharger|default=""}' class="layui-input layui-bg-gray">
				<input name="doccharger" value='{$vo.doccharger|default=""}' type="hidden" class="layui-input layui-bg-gray">
                {else}
				<div id="doccharger" class="xm-select-demo"></div>
				{/if}
                <!-- <input name="doccharger" value='{$vo.doccharger|default=""}' required placeholder="请输入拟办人" class="layui-input"> -->
            </div>
        </div>
		
		
        <div class="layui-form-item">
            <label class="layui-form-label ">批示领导</label>
            <div class="layui-input-block">
				<div id="docleader" class="xm-select-demo"></div>
                <!--<input name="docleader" value='{$vo.docleader|default=""}' placeholder="" class="layui-input">-->
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">传阅人</label>
            <div class="layui-input-block">
				<div id="docread" class="xm-select-demo"></div>
                <!--<input name="docread" value='{$vo.docread|default=""}'  placeholder="" class="layui-input">-->
            </div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label ">办理人</label>
            <div class="layui-input-block">
				<div id="docdo" class="xm-select-demo"></div>
                <!--<input name="docdo" id="docdo" value='{$vo.docdo|default=""}'  placeholder="" class="layui-input">-->
            </div>
        </div>
		
		
        <div class="layui-form-item">
            <label class="layui-form-label ">文件列表</label>
            <div class="layui-input-block">
                <div class="layui-textarea padding-bottom-10" style="min-height:auto">
					<div class="layui-upload">
					  {if auth("edit") && request()->action() =='edit'  && $vo['docauthor']==session('admin_user')['nickname'] && $vo['status']!=2 }
					  <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="testList">选择多文件</button> &nbsp;&nbsp;
					  <button type="button" class="layui-btn layui-btn-sm" id="testListAction">开始上传</button>
					  {/if}
					  
					  {if auth("add") && request()->action() =='add'  }
					  <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="testList">选择多文件</button> &nbsp;&nbsp;
					  <button type="button" class="layui-btn layui-btn-sm" id="testListAction">开始上传</button>
					  {/if}				  
					  
					  
					  
					  <div class="layui-upload-list">
						<table class="layui-table">
						  <thead>
							<tr><th>文件名</th>
							<th>大小</th>
							<th>状态</th>
							<th>操作</th>
						  </tr></thead>
						  <tbody id="demoList">
						  {foreach $files as $key=>$vo}
						  <tr id="upload-{$vo.fileid}"><td>{$vo.original_name}</td><td>{$vo.filesize|format_size}</td><td></td><td> <a target="new" href="{$vo.fileurl}">查看</a></td>  <tr>
						  {/foreach}
						  </tbody>
						</table>
					  </div>
					  
					</div> 


                </div>
            </div>
        </div>
		
		{if request()->action() =='edit'}
        <div class="layui-form-item">
            <label class="layui-form-label ">批示情况</label>
            <div class="layui-input-block">
                <div class="layui-textarea padding-bottom-10" style="min-height:auto">

						<table class="layui-table">
						  <thead>
							<tr>
							<th>批示人</th>
							<th>批示时间</th>
							<th>批示类型</th>
							<th width="40%">批示内容</th>
						  </tr></thead>
						  {foreach $list_flow as $key=>$vo}
						  <tr id="upload-{$vo.id}">
						  <td>{$vo.username}</td>
						  <td>{$vo.creat_at|format_datetime='Y-m-d H:i'}</td>
						  
						  <td>                
						  {eq name='vo.types' value='shouwen'}<span class="layui-bg-red">收文经办</span>{/eq}
						  {eq name='vo.types' value='doccharger'}<span class="layui-bg-orange">拟办意见</span>{/eq}
						  {eq name='vo.types' value='docleader'}<span class="layui-bg-green">领导批示</span>{/eq}
						  {eq name='vo.types' value='docread'}<span class="layui-bg-blue">传阅情况</span>{/eq}
						  {eq name='vo.types' value='docdo'}<span class="layui-bg-black">办理情况</span>{/eq}
						  </td>
						  
						  <td> {$vo.info}</td>  <tr>
						  {/foreach}
						</table>

                </div>
            </div>
        </div>
		{/if}
		
		
		
		
		
		
		{if request()->action() =='edit' && $rs_flow >0 }
        <div class="layui-form-item">
            <label class="layui-form-label">填写意见</label>
            <div class="layui-input-block">

				<textarea class="layui-textarea" name="info" id="info" placeholder="请填写批示意见">{$info|default=""}</textarea>

            </div>
			
        </div>
		
        <div class="layui-form-item">
			<div class="layui-input-inline margin-right-0" style="width:300px">
				<label class="layui-form-label">常用批示（快捷回复）</label>
				<div class="layui-input-block">

				  <select name="pishi" id="pishi" lay-filter="pishi">
					
					
					<option value=""></option>
					{foreach $pishi as $key=>$vo}
					<option value="{$vo}">{$vo}</option>

					{/foreach}
					
					<option value="已阅">已阅</option>
					<option value="拟同意">拟同意</option>
					<option value="已办理">已办理</option>

				  </select>
				  
				</div>  
            </div>
			
            <label class="layui-form-label ">电子签名</label>
            <div class="layui-input-inline margin-right-0" style="width:164px">
			  <select name="signature" id="signature">

				<option value=""></option>
				{foreach $signature_list as $key=>$vo}
				<option value="{$vo.sigurl}">{$vo.sigtitle}</option>
				{/foreach}

			  </select>
            </div>
			
			
        </div>
		
		
		{/if}
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='id'}<input type='hidden' value='{$id}' name='id' id="id">{/notempty}
	<input type='hidden' value='{$docauthor}' name='docauthor'>
    <div class="layui-form-item text-center">
		{if request()->action() =='edit' && $rs_flow >0 }
		<button class="layui-btn" type='button' id="saveinfo">保存批示意见</button>
		{/if}
		
		{if request()->action() =='edit' && $docauthor == session('admin_user.nickname')  }
        <button class="layui-btn" type='submit'>流转文件</button>
		{/if}
		{if request()->action() =='add' }
		<button class="layui-btn" type='submit'>保存数据</button>
		{/if}
        <!-- <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要关闭吗？" data-close>关闭</button> -->
		<button class="layui-btn layui-btn-danger" onclick="hsitoryBack()" type="button">关闭</button>
    </div>

    <script>

	window.form.render();
	
	function hsitoryBack(){
		$.msg.confirm('确定要关闭吗？', function (index) {
			history.back(), $.msg.close(index);
		});
	};
	
	

	</script>

</form>

<script>
    layui.use(['layer','form' ,'jquery'], function() {
        var layer = layui.layer, $ = layui.jquery ,form = layui.form;
		
		form.on('select(pishi)', function(data){
		  //console.log(data.value); //得到被选中的值
		  $("#info").val(data.value)
		  //$("#pishi").val(data.value)
		  //$("#pishi").empty();
		}); 
		
        form.render();
    });
	

	$('#saveinfo').click(function(){
		var info = $("#info").val();
		var docid =$("#id").val();
		var signature =$("#signature").find("option:selected").val(); //=$("#signature").val();
		if (typeof(info) == "undefined")
		{
			layer.msg('数据错误!',{icon: 5});//失败的表情
			return ;
		}
		
		if(info == ''){
			layer.msg('请填写批示意见!',{icon: 5});//失败的表情
			return ;		
		}
		
		
		var url = "/document/doc/saveinfo.html";
		$.ajax({
			url:url,
			type:'post',
			data:'info='+info+'&docid='+docid+'&signature='+signature,
			beforeSend:function () {
				
				this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
			},
			success:function(data){
				if(data.status == 'error'){
					layer.msg(data.msg,{icon: 5});//失败的表情
					return;
				}else if(data.status == 'success'){
					//layer.msg(data.msg,{icon: 6});
					layer.msg(data.msg, {
						icon: 6,//成功的表情
						time: 2000 //1秒关闭（如果不配置，默认是3秒）
					}, function(){
						//location.reload();
						window.location.href="/admin.html#/document/doc/index.html?spm=m-62-63-64";
					});
				}
			},
			complete: function () {
				layer.close(this.layerIndex);
			},
		});
		return false;//阻止表单跳转
	});

</script>


{/block}